import random

from models.post import BoardModel,PostModel
from models.auth import UserModel
from exts import db

def init_board():
    board_list=['Python','Java','Flask','Django','前端','Qt']
    for index,name in enumerate(board_list):
        board=BoardModel(name=name,priority=len(board_list)-index)
        db.session.add(board)
    db.session.commit()
    print("版块初始化成功!")

def init_posts():
    boards=BoardModel.query.all()
    board_count=len(boards)
    user=UserModel.query.first()
    for i in range(100):
        board=boards[random.randint(0,board_count-1)]
        post=PostModel(title='帖子%d'%i,content="内容%d"%i,board=board,author=user)
        db.session.add(post)
    db.session.commit()
    print("帖子初始化成功!")